import {AcGameObject} from "./game_object.js";
import {Controller} from "./controller.js";

class GameMap extends AcGameObject {

    constructor(root) {
        super();

        this.root = root
        this.$canvas = $(
            `
                <canvas width="1280px" height="720px" tabindex=0></canvas>
            `
        )

        this.ctx = this.$canvas[0].getContext('2d')
        this.root.$kof.append(this.$canvas)
        this.$canvas.focus()

        this.controller = new Controller(this.$canvas)
        this.time_left = 60000 // 单位: ms
        this.$timer = this.root.$kof.find(".kof-head-timer")
        console.log(this.$timer)
    }

    start() {

    }

    update() {
        this.time_left = Math.max(this.time_left - this.timedelta, 0)
        this.$timer.text(Math.floor(this.time_left / 1000))

        if (this.time_left <= 0) {
            let [a, b] = this.root.players
            if (a.status !== 6 && b.status !== 6) {
                a.status = 6
                b.status = 6
                a.frame_current_cnt = 0
                b.frame_current_cnt = 0
            }
        }
        this.render()
    }

    render() {
        this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height)

        // // 为方便调试，暂时把背景画成黑色
        // this.ctx.fillStyle = 'black'
        // this.ctx.fillRect(0, 0, this.$canvas.width(), this.$canvas.height())
    }
}

export {
    GameMap
}